<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <script src="./js/earthsdk.js"></script>

    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css" />
    <title>poi聚合</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .server,
        .box {
            display: grid;
            align-items: center;
            grid-template-columns: 100px 1fr;
            grid-row-gap: 5px;
            margin-bottom: 10px;
        }

        .box1 {
            display: grid;
            grid-template-columns: 1fr;
        }

        .scale {
            display: flex;
            justify-content: space-between;
        }

        .scale>input {
            width: 30%;
            height: 20px;
        }

        .tip {
            color: rgb(255, 255, 0);
            font-size: 14px;
            padding-bottom: 10px;
            border-bottom: 2px dotted #979797;
        }

        #GroupColor1,
        #GroupColor2 {
            background-color: rgb(0, 255, 0);
            width: 30px;
            height: 30px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="content">地址</label>
            <input type="text" id="url" value="https://www.earthsdk.com/assets/cun.json" onchange="setUrl()" />
            <label for="content">聚合范围</label>
            <input type="text" id="pixelRange" value="200" onchange="setScope()" />
            <label for="content">最小数量</label>
            <input type="text" id="minimumClusterSize" value="2" onchange="setMin()" />
            <label for="content">高度模式</label>
            <select name="mode" id="heightReference" onchange="setMode()">
                <option value="None" selected>None</option>
                <option value="CLAMP_TO_GROUND">CLAMP_TO_GROUND</option>
                <option value="CLAMP_TO_TERRAIN">CLAMP_TO_TERRAIN</option>
            </select>
        </div>
        <!-- <div class="box1">
        <button onclick="flyTo()">飞行定位</button>
        <button onclick="printJson()">控制台打印JSON</button>
      </div> -->
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn([112.23837998083044, 23.995489863145785, 1084526.6070480016], [10.383676658199555, -89.9639505324624, 0], 3)
        });

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            id: "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            type: "ESImageryLayer",
            url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
        });

        /** ---------------------------------poi聚合------------------------------------**/
        const sceneObject = objm.createSceneObject('ESEntityCluster');
        sceneObject.url = "https://www.earthsdk.com/assets/cun.json"
        sceneObject.pixelRange = 200
        sceneObject.minimumClusterSize = 2
        sceneObject.heightReference = "None"

        // 设置地址
        const setUrl = () => {
            sceneObject.url = document.getElementById("url").value
        }

        // 设置聚合范围
        const setScope = () => {
            sceneObject.pixelRange = document.getElementById("pixelRange").value
        }
        // 设置最小数量
        const setMin = () => {
            sceneObject.minimumClusterSize = document.getElementById("minimumClusterSize").value
        }

        // 设置高度模式
        const setMode = () => {
            sceneObject.heightReference = document.getElementById("heightReference").value
        }

    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>